package com.xxx.gmail.UI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class MainFrm {

	public static JFrame frame;
	public static JTabbedPane tabbedPane;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrm window = new MainFrm();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainFrm() {
		initialize();
	}
	
	private void createTab(BasePane panel){
		for (int i = 0; i < tabbedPane.getTabCount(); i++) {
			if (panel.paneltitle.equals(tabbedPane.getTitleAt(i))){
			tabbedPane.setSelectedIndex(i);		
			return;
			}
		}
		tabbedPane.addTab(panel.paneltitle, panel);	
		for (int i = 0; i < tabbedPane.getTabCount(); i++) {
			if (panel.paneltitle.equals(tabbedPane.getTitleAt(i)))
			tabbedPane.setSelectedIndex(i);				
		}		
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		try {
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout(0, 0));
		
		JToolBar toolBar = new JToolBar();
		frame.getContentPane().add(toolBar, BorderLayout.NORTH);
		
		final JButton button = new JButton("用户管理列表");
		button.addActionListener(new ActionListener() {			
			public void actionPerformed(ActionEvent actionevent) {
				createTab(new CustomerListPane());
			}
		});
		toolBar.add(button);
		
		final JButton button_1 = new JButton("用户管理录入");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				createTab(new CustomerDetailsPane());
			}
		});
		toolBar.add(button_1);
		
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.SOUTH);
		
		JLabel label = new JLabel("登录用户：管理员");
		panel.add(label);
		
		tabbedPane = new JClosableTabbedPane();
		frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("首页", panel_1);
		panel_1.setLayout(new BorderLayout(0, 0));
		
		JTextPane textPane = new JTextPane();
		panel_1.add(textPane);
		
		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);
		
		JMenu menu = new JMenu("用户管理");
		menuBar.add(menu);
		
		JMenuItem menuItem = new JMenuItem("用户管理列表");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				createTab(new CustomerListPane());	
			}
		});
		menu.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("用户管理新增");
		menuItem_1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				createTab(new CustomerDetailsPane());		
			}			
		});
		menu.add(menuItem_1);	
	}

}
